﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using wh40klbModel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Database.SetInitializer(new DbInitializer());
            using (var context=new wh40klbModel.WarhammerContext())
            {
                try
                {                 
                    context.Database.Initialize(force:true);
                    foreach (var item in context.SquadTypes)
                    {
                        Console.WriteLine(item.Name);
                    }
                }
                catch (Exception ex)
                {
                    context.Database.Connection.Close();
                    context.Dispose();
                    Console.WriteLine("Initialization Failed...");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("\n\n");
                    Console.WriteLine(ex.StackTrace);
                }                
            }          
            Console.WriteLine("\nPress key to end program...");
            Console.Read();
        }
    }



    class DbInitializer:DropCreateDatabaseAlways<wh40klbModel.WarhammerContext>
    {
        protected override void Seed(WarhammerContext context)
        {
            new List<SquadType>{
                new SquadType{ Name="QG",availible=true},
                new SquadType{ Name="Elite",availible=true},
                new SquadType{ Name="Troupe",availible=true},
                new SquadType{ Name="Attaque rapide",availible=true},
                new SquadType{ Name="Soutien",availible=true},
                new SquadType{ Name="Transporter",availible=true}
            }.ForEach(c=>context.Entry<SquadType>(c).State=System.Data.EntityState.Added);




            context.SaveChanges();
        }
    }


}
